package com.cskaoyan.controller.goods;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.bo.goods.*;
import com.cskaoyan.bean.vo.goods.AdminGoodsCatAndBrandVO;
import com.cskaoyan.bean.vo.goods.AdminGoodsDetailVO;
import com.cskaoyan.bean.vo.goods.AdminGoodsListVO;
import com.cskaoyan.service.goods.AdminGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 冯子靖
 * @Description:
 * @Date: 2022/7/18 21:33
 */
@RestController
@RequestMapping("admin/goods")
public class AdminGoodsController {

    @Autowired
    AdminGoodsService adminGoodsService;

    /**
     * 商品清单
     *
     * @param adminGoodsBO
     * @return
     */
    @GetMapping("list")
    public BaseRespVo printAdminGoodsList(AdminGoodsBO adminGoodsBO) {
        AdminGoodsListVO adminGoodsListVO = adminGoodsService.printAdminGoodsList(adminGoodsBO);

        return BaseRespVo.ok(adminGoodsListVO);
    }

    /**
     * 添加商品界面的下拉清单
     */
    @GetMapping("catAndBrand")
    public BaseRespVo printAdminGoodsCatAndBrand() {
        AdminGoodsCatAndBrandVO adminGoodsCatAndBrandVO = adminGoodsService.printAdminGoodsCatAndBrand();
        return BaseRespVo.ok(adminGoodsCatAndBrandVO);
    }

    /**
     * 添加商品
     */
    @PostMapping("create")
    public BaseRespVo createAdminGoods(@RequestBody AdminGoodsCreateBO adminGoodsCreateBO) {
        adminGoodsService.insertGoods(adminGoodsCreateBO);
        return BaseRespVo.ok();
    }

    /**
     * 显示商品详情
     */
    @GetMapping("detail")
    public BaseRespVo showAdminGoodsDetail(Integer id) {

        AdminGoodsDetailVO detailVO = adminGoodsService.showGoodsDetail(id);

        return BaseRespVo.ok(detailVO);
    }

    /**
     * 更新商品
     */
    @PostMapping("update")
    public BaseRespVo updateAdminGoods(@RequestBody AdminGoodsUpdateBO adminGoodsUpdateBO) {
        adminGoodsService.updateGoods(adminGoodsUpdateBO);
        return BaseRespVo.ok();
    }

    /**
     * 删除商品和其他相关数据(逻辑删除)
     */
    @PostMapping("delete")
    public BaseRespVo deleteAdminGoods(@RequestBody AdminGoodsDeleteBO adminGoodsDeleteBO) {

        adminGoodsService.deleteGoods(adminGoodsDeleteBO);

        return BaseRespVo.ok();
    }
}
